<?php

namespace app\common\model\banxi;

use app\common\model\banxi\Sms as SmsModel;
use app\common\model\common\BaseModel;

/**
 * Attachment模型
 * @property string url              文件物理路径
 * @property int quote            上传(引用)次数
 * @property int last_upload_time 最后上传时间
 */
class Sms extends BaseModel
{
    protected $name = 'banxi_sms';

    protected $autoWriteTimestamp = true;

    //-----------------------------------------------------------------------------------
    //｜                                   获取器                                       ｜
    //-----------------------------------------------------------------------------------



    //-----------------------------------------------------------------------------------
    //｜                                   处理方法                                       ｜
    //-----------------------------------------------------------------------------------

    public function saveCode($phone, $code, $type, $ip)
    {
        $condition = ['mobile' => $phone, 'event' => $type];
        $data = array_merge($condition, [
            'code' => $code,
            'ip' => $ip,
            'times' => 0
        ]);
        // 查找是否存在记录
        if ($this->where($condition)->count()) {
            // 更新现有记录
            $this->where($condition)->update($data);
        } else {
            // 创建新记录
            $this->save($data);
        }
        return true;
    }


    //-----------------------------------------------------------------------------------
    //｜                                   模型关联                                       ｜
    //-----------------------------------------------------------------------------------


}